let baseUrl = 'https://www.mycuo.com/api/video-wiki-qa';
import sortBy from 'lodash/sortBy';

export const setUp = url => baseUrl = url;
export function fetchQuestions() {
  return fetch(`${baseUrl}/question`, {credentials: 'same-origin'})
    .then(res => res.status < 400 ? res.json() : Promise.reject({message: res.statusText}))
    .then(({questions}) => questions);
}

export function answer(questionId, answerId) {
  return fetch(`${baseUrl}/answer?question=${questionId}&answer=${answerId}`, {credentials: 'same-origin'})
    .then(res => res.json())
}

export function getWiki() {
  return fetch(`${baseUrl}/wiki`, {credentials: 'same-origin'})
    .then(res => res.json())
}
